package cn.tedu.d21_socket;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 以太网适配器 以太网:
 连接特定的 DNS 后缀 . . . . . . . :
 本地链接 IPv6 地址. . . . . . . . : fe80::393c:ba80:89e0:234c%2
 IPv4 地址 . . . . . . . . . . . .: 172.199.11.43
 子网掩码  . . . . . . . . . . . . : 255.255.255.192
 默认网关. . . . . . . . . . . . . : 172.199.11.1
 */
/*
 Socket-服务端
 */
public class Server {
    public static void main(String[] args) throws Exception {

        ServerSocket sever = new ServerSocket(8888);//0-65535
        System.out.println("服务器已开启...");
        Socket socket = sever.accept();//侦听

        System.out.println("接收到一个连接请求...");
        BufferedReader br = new BufferedReader(
                new InputStreamReader(socket.getInputStream()));

        PrintWriter pw = new PrintWriter(socket.getOutputStream(),true);

/*        while(true) {

            for (int i = 0; i <5; i++) {
                //if(in.read()==-1) break;
                char a = (char) in.read();
                System.out.print(a);
            }*/
        while (true) {
            String s=br.readLine();
            System.out.print(s);
            System.out.print(" :客户");

            System.out.println("");

            System.out.print("我:");
            String str = new Scanner(System.in).nextLine();
            pw.println(str);
            //pw.flush();
        }
    }

    //out.flush();






}

